import api from '../index';
import type { ResponseData, pageParam, RequestFromType } from '../index';
// 注册
export const postRegister = (data: { userName: string; password: string; validCode: string; countryId?: number; salt?: string,referencePhone?:string },tenant?:string) =>
	api.post('customer/api/register', {
		data,
		header:tenant? {
			tenant
		} :undefined, 
		custom: {
			auth: false,
			isLoading: true,
			showMsg: true
		}
	});
// 注册短信
export const postRegisterSms = (phone: string, data?: { countryId?: number }) =>
	api.post(`customer/api/sms/register/${phone}`, {
		data,
		custom: {
			auth: false,
			showMsg: true
		}
	});

export type RequestLoginData = ResponseData<{
	access_token?: string;
	openid?: string;
}>;

// 登录
export const postLogin = (data: { areaCode: string; username: string; password: string }) =>
	api.post<RequestLoginData>('auth/api/customer/login', {
		data,
		custom: {
			auth: false,
			isLoading: true
		}
	});
// 绑定手机号
export const postBindPhone = (data: { wxCode: string; openid: string; salt?: string } | { validCode: string; phone: string }) =>
	api.put('customer/api/bindPhone', {
		data,
		custom: {
			auth: false,
			isLoading: true
		}
	});
export interface BasicsSetting {
	agreements: { id: number; status: 1 | 0 }[];
	customerInfos: [];
	registerModel: string;
	registerType: string;
}
// 用户协议列表与注册规则
export const getBasicsSetting = () =>
	api.get<ResponseData<BasicsSetting>>('system/api/basics/customer', {
		custom: {
			auth: false
		}
	});
// 修改登录密码
export const postResetLoginPassword = (data: { userName: string; password: string; validCode: string }) =>
	api.put('customer/api/updatePassword', {
		data,
		header: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		custom: {
			auth: false,
			isLoading: true
		}
	});

// 退出登录
export const logout = () => api.delete('auth/api/customer/logout');
// 微信登录
export const postWxLogin = (data: { code: string }) =>
	api.post<ResponseData<{ access_token: string; openid: string }>>('auth/api/customer/ma/login', {
		data,
		custom: {
			auth: false,
			isLoading: true
		}
	});
// 支付宝登录
export const postAliLogin = (data: { code: string; salt?: string }) =>
	api.post('auth/api/customer/ali/ma/login', {
		data,
		custom: {
			auth: false,
			isLoading: true
		}
	});
// 当前支持的登录鉴权列表
export const getOAuthList = () =>
	api.get<ResponseData<{ authType: string }[]>>('system/api/basics/oauth', {
		custom: {
			auth: false,
			isLoading: true
		}
	});

// app 微信登录
export const postAppWxLogin = (data: { code: string }) =>
	api.post<RequestLoginData>('api/customer/wx/app/login', {
		data,
		custom: {
			auth: false,
			isLoading: true
		}
	});
// // app Google登录
// export const postAppGoogleLogin = data =>
// 	api({
// 		url: 'auth/api/customer/ma/login',
// 		method: 'post',
// 		data
// 	}, {
// 		auth: false,
// 		isLoading: true
// 	})
// // app Facebook登录
// export const postAppFacebookLogin = data =>
// 	api({
// 		url: 'auth/api/customer/ma/login',
// 		method: 'post',
// 		data
// 	}, {
// 		auth: false,
// 		isLoading: true
// 	})

export interface CountryAreaItem {
	id: number;
	countryName: string;
	countryCode: string;
	countryArea: string;
	logo?:string
}
// 获取国家手机号列表
export const getPhonePrefix = () =>
	api.get<ResponseData<CountryAreaItem[]>>('system/api/basics/phonePrefix', {
		custom: {
			auth: false
		}
	});

// 账号注销
export const logOff = (data:any) => api.get('customer/api/logOff',{data});

// 绑定邮箱
export const postBindEmail = (data: any) =>
	api.post('customer/api/bindEmail', {
		data
	});
export interface AuthenticationParams  {
	idcard: string
	realName: string
	linkPhone: string
	front: string
	back: string
}
//提交实名认证
export const addAuthentication = (data: AuthenticationParams) =>
  api.post("customer/api/authen", {
    data,
    custom: {
      isLoading: true,
	  showMsg:true
    },
	header: {
		'Content-Type': 'application/json'
	}
  });

//实名认证记录
export const authenLogn = () =>
  api.get<
    ResponseData<{
      status: number;
      idcard: string;
      linkPhone: string;
      realName: string;
      remark: string;
    }>
  >("customer/api/authenLog", {
    custom: {
      isLoading: true,
    },
  });
